local skel =fk.CreateSkill{
    name = "history__lisuo",
}


Fk:loadTranslationTable{
    ["history__lisuo"] = "栗索",
    [":history__lisuo"] = [[出牌阶段限一次，你可以与一名有手牌的其他角色同时展示任意张手牌，若其展示牌的数量
：小于你，其于下个出牌阶段内至多使用其展示牌数张牌。
大于你，你重铸你展示的所有牌，然后对其使用至多X张不计入次数且无距离次数限制的【杀】（X为其与你展示牌数之差）]],

["#history__lisuo_showcards"] = "栗索：请展示你的手牌",
["@history__lisuo"] = "栗索",
["#history__lisuo-use"] = "你可以使用一张无距离次数限制【杀】",
}

skel:addEffect("active",{
    anim_type = "offensive",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
      return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
    end,
    card_filter = function(self, player, to_select, selected)
      return false
    end,
    target_filter = function(self, player, to_select, selected, selected_cards)
      return #selected == 0 and to_select ~= player and not to_select:isKongcheng()
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local target = effect.tos[1]
        local targets = { player, target } ---@type ServerPlayer[]
        local result = room:askToJointCards(player, {
            players = targets,
            min_num = 0,
            max_num = 99,
            include_equip = false,
            skill_name = skel.name,
            cancelable = false,
            prompt = "#history__lisuo_showcards",
          })
        for _, p in ipairs(targets) do
            p:showCards(result[p])          
        end
        local player_num = #result[player]
        local target_num = #result[target]
        if player_num < target_num then
            room:recastCard(player:getCardIds("h"), player, skel.name)
            local x=target_num-player_num
            for i=1 , x do
                local use = room:askToUseCard(player, {
                    pattern = "slash",
                    skill_name = "slash",
                    prompt = "#history__lisuo-use",
                    cancelable = true,
                    extra_data = {
                      bypass_distances = true,
                      bypass_times = true,
                    },
                })
            end
            
        elseif player_num > target_num then
            room:setPlayerMark(target,"@history__lisuo",target_num)
        end
    end,
})

skel:addEffect(fk.CardUseFinished, {
    can_refresh = function (self, event, target, player, data)
      return target == player and  player.phase == Player.Play and 
      player:getMark("@history__lisuo")>0 
    end,
    on_refresh = function (self, event, target, player, data)
      local room = player.room
      room:addPlayerMark(player, "history__lisuo-phase")
    end,
  })
  skel:addEffect(fk.TurnEnd, {
    can_refresh = function (self, event, target, player, data)
      return target == player and target:getMark("@history__lisuo")>0
    end,
    on_refresh = function (self, event, target, player, data)
      local room = player.room
      room:setPlayerMark(player, "@history__lisuo",0)
    end,
  })


  skel:addEffect("prohibit", {
    prohibit_use = function(self, player)
      return player.phase == Player.Play and player:getMark("@history__lisuo")>0 and 
      player:getMark("history__lisuo-phase") >= player:getMark("@history__lisuo")
    end,
  })


return skel